package com.song.controller.gxtp;

import com.song.model.ResultEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.song.entity.gxtp.GxtpRygx;
import com.song.service.gxtp.GxtpRygxService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.ObjectUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.Serializable;
/**
* <p>
    * 关系图谱_人员关系 控制器
    * </p>
*
* @author song
* @since 2025-01-21
*/
@Api(tags = {"关系图谱_人员关系 控制器"})
@RestController
@RequestMapping("/gxtp_rygx")
public class GxtpRygxController {

    @Autowired
    GxtpRygxService gxtpRygxService;

    /**
    * 分页查询数据
    *
    * @author song
    * @Date 2025-01-21
    */
    @ApiOperation(value = "按条件分页检索关系图谱_人员关系",notes = "按条件分页检索关系图谱_人员关系")
    @GetMapping(value = "/pageList")
    public ResultEntity<Page<GxtpRygx>> pageList(
        @Validated GxtpRygx gxtpRygx,
        @ApiParam(value = "页码", defaultValue = "1")
        @RequestParam(defaultValue = "1") int pageNum,
        @ApiParam(value = "分页大小", defaultValue = "10")
        @RequestParam(defaultValue = "10") int pageSize
    ) {
        Page<GxtpRygx> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<GxtpRygx> lambda = new QueryWrapper<GxtpRygx>().lambda();
        if(ObjectUtils.isNotEmpty(gxtpRygx.getGmsfhmMaster())){
            lambda.eq(GxtpRygx::getGmsfhmMaster,gxtpRygx.getGmsfhmMaster());
        }
        if(ObjectUtils.isNotEmpty(gxtpRygx.getGmsfhmSlave())){
            lambda.eq(GxtpRygx::getGmsfhmSlave,gxtpRygx.getGmsfhmSlave());
        }
        if(ObjectUtils.isNotEmpty(gxtpRygx.getRygx())){
            lambda.eq(GxtpRygx::getRygx,gxtpRygx.getRygx());
        }
        return ResultEntity.success(gxtpRygxService.page(page,lambda));
    }

    /**
    * 查询数据List
    *
    * @author song
    * @Date 2025-01-21
    */
    @ApiOperation(value = "查询全部关系图谱_人员关系",notes = "查询全部关系图谱_人员关系")
    @GetMapping(value = "/list")
    public ResultEntity<List<GxtpRygx>> list() {
        List<GxtpRygx> gxtpRygxList = gxtpRygxService.list();
        return ResultEntity.success(gxtpRygxList);
    }

    /**
    * 关系图谱_人员关系新增
    *
    * @author song
    * @Date 2025-01-21
    */
    @ApiOperation(value = "新增关系图谱_人员关系",notes = "新增关系图谱_人员关系")
    @PostMapping(value = "/add")
    public ResultEntity add(@RequestBody GxtpRygx gxtpRygx) {
        boolean exists = gxtpRygxService.checkExists(gxtpRygx);
        if (exists){
            return ResultEntity.failMessage("人员关系已存在！");
        }
        gxtpRygxService.save(gxtpRygx);
        return ResultEntity.success();
    }

    /**
    * 关系图谱_人员关系修改
    *
    * @author song
    * @Date 2025-01-21
    */
    @ApiOperation(value = "修改关系图谱_人员关系",notes = "修改关系图谱_人员关系")
    @PostMapping(value = "/update")
    public ResultEntity edit(@RequestBody GxtpRygx gxtpRygx) {
        gxtpRygxService.updateByDoubleId(gxtpRygx);
        return ResultEntity.success();
    }

    /**
    * 删除关系图谱_人员关系
    *
    * @author song
    * @Date 2025-01-21
    */
    @ApiOperation(value = "按id删除关系图谱_人员关系",notes = "按id删除关系图谱_人员关系")
    @PostMapping(value = "/delete")
    public ResultEntity delete(@RequestParam String gmsfhmMaster, @RequestParam String gmsfhmSlave) {
        gxtpRygxService.removeByDoubleId(gmsfhmMaster, gmsfhmSlave);
        return ResultEntity.success();
    }
}